package com.netty.esc.config.neo4j;



import org.neo4j.driver.internal.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.transaction.ChainedTransactionManager;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * @ClassName: 11094
 * @Description:
 * @Author: zy
 * @Date: 2022/11/14 22:00
 * TODO: 事务问题需要解决
 **/
@Configuration
@EnableNeo4jRepositories(basePackages = "com.netty.esc.dao.repository")// 开启Neo4jRepositories的支持
//@EntityScan(basePackages = "com.phkg.entity")// 开启实体类扫描
@EnableTransactionManagement // 开启事务
public class Neo4jConfig {

    // 1. 此处为了修改默认事务，必须改。加载了Neo4J依赖库之后，transactionManager变成Neo4jTransactionManager，不增加此处，启动会报错，Mysql无法使用。
//    @Bean("transactionManager")
//    @Primary
//    public DataSourceTransactionManager transactionManager(DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//    @Bean("neo4jTransactionManager")
//    public Neo4jTransactionManager neo4jTransactionManager(SessionFactory sessionFactory) {
//        return new Neo4jTransactionManager(sessionFactory);
//    }

//    @Autowired
//    @Bean(name = "multiTransactionManager")
//    public PlatformTransactionManager multiTransactionManager(
//            Neo4jTransactionManager neo4jTransactionManager,
//            DataSourceTransactionManager mysqlTransactionManager) {
//        return new ChainedTransactionManager(
//                neo4jTransactionManager, mysqlTransactionManager);
//    }

}
